package com.ruiysoft.website.controller;

import com.ruiysoft.website.entity.CmsContent;
import com.ruiysoft.website.entity.CmsContentDetail;
import com.ruiysoft.website.service.CmsContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by liudh on 2019/4/25.
 */

@RestController
@RequestMapping("content")
public class CmsContentController {
    @Autowired
    CmsContentService cmsContentService;

//    @Cacheable(value="selectListByEnterpriseIdAndCatalogCode")
    @GetMapping("selectListByEnterpriseIdAndCatalogCode")
    public Object selectListByEnterpriseIdAndCatalogCode(Integer enterpriseId, String catalogCode) {
        return cmsContentService.selectLeftJoinCatalog(enterpriseId, catalogCode);
    }

//    @Cacheable(value="selectDetailByContentId")
    @GetMapping("selectDetailByContentId")
    public Object selectDetailByContentId(Integer id) {
        return cmsContentService.selectDetailByContentId(id);
    }

//    @CacheEvict(value="selectDetailByContentId", allEntries=true)
    @PostMapping("saveOrEdit4Detail")
    public Object saveOrEdit4Detail(@RequestBody CmsContentDetail obj) {
        return cmsContentService.saveOrEdit4Detail(obj);
    }

//    @CacheEvict(value="selectListByEnterpriseIdAndCatalogCode", allEntries=true)
    @PostMapping("saveOrEdit")
    public Object saveOrEdit(@RequestBody CmsContent cmsContent) {
        return cmsContentService.saveOrEdit(cmsContent);
    }

//    @CacheEvict(value="selectListByEnterpriseIdAndCatalogCode", allEntries=true)
    @GetMapping("deleteById")
    public Object deleteById(Integer id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("success", false);

        int rtn = cmsContentService.deleteById(id);
        if(rtn > 0)
            map.put("success", true);

        return map;
    }

}

